using UnityEngine;
using System.Collections;

public class CameraScript : Reaction {
	
	Transform thisTransform;
	Vector3 startPosition;
	
	void Start () {
		thisTransform = transform;
		startPosition = thisTransform.position;
	}
	
	override protected void pain(float amount)
	{
		StopCoroutine("shake");
		StartCoroutine("shake", amount);
	}
	
	IEnumerator shake(float modifier)
	{
		thisTransform.position = startPosition;
		Vector3 initPos = thisTransform.position;
		Vector3 shakePos = new Vector3();
		shakePos.z = initPos.z;
		float shakeTime = 0;
		while(shakeTime < .5f)
		{
			shakePos.x = initPos.x + 0.2f * modifier * Mathf.Sin(shakeTime * 50);
			shakePos.y = initPos.y + 0.2f * modifier * Mathf.Cos(shakeTime * 60);
			thisTransform.position = shakePos;
			
			yield return 0;
			shakeTime += Time.deltaTime;
		}
	}
}
